package com.shujia.mr.DianXin2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

import java.io.IOException;

//<0L,"00595A38A1F98846E4F788276F34173EC758BC20-83401-8340104	26">
//<0L,"81101,北京市">
//输出reduce<"81101"，[times,city]>
//
//reduce输入<"1001",["$20180603-50","#万寿福宫，北京"]>
//reduce输出<"20180603-万寿福宫，北京","50">
public class DianXinMapper2 extends Mapper<LongWritable,Text,Text,Text> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        FileSplit inputSplit = (FileSplit) context.getInputSplit();
        String FileName = inputSplit.getPath().getName();
        String cityId = null;
        String cityName = null;
        String time = null;
        if (FileName.startsWith("city")) {
            //这是城市id文件
            String[] infos = line.split(",");
             cityId = infos[0];
             cityName = infos[1];
            context.write(new Text(cityId),new Text("#"+ cityName));
        }else if (FileName.startsWith("part")){
            //这是个人停留平均时间文件
            String[] infos = line.split("-");
            String[] times = infos[2].split("\t");
             cityId = infos[1];
            String PhoneNumber = infos[0];
            time = times[1];
            context.write(new Text(cityId),new Text("*"+ PhoneNumber+"-"+time));
        }

    }
}
